package logic

import (
	"cart_srv/models/redis"
	"context"
	"errors"
	"fmt"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewDeleteCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteCartLogic {
	return &DeleteCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *DeleteCartLogic) DeleteCart(in *cart.DeleteCartRequest) (*cart.DeleteCartResponse, error) {
	// todo: add your logic here and delete this line

	err := redis.DelCart(int(in.UserId), int(in.GoodsId))
	if err != nil {
		return nil, errors.New("删除失败")
	}
	fmt.Println("删除成功")
	return &cart.DeleteCartResponse{}, nil
}
